package com.example.book.dao.impl;

import com.example.book.dao.BorrowDao;
import com.example.book.model.Borrow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Repository
public class BorrowImpl implements BorrowDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public int insert(Borrow borrow) {
        return 0;
    }

    @Override
    public int delete(String id) {
        return 0;
    }

    @Override
    public int update(Borrow borrow) {
        return 0;
    }

    @Override
    public Borrow queryById(String id) {
        return null;
    }

    @Override
    public Integer insert(String userId, String bookId) {
        String sql = "insert into borrow(book_id, user_id, borrow_date) values (?,?,?)";
        return jdbcTemplate.update(sql,bookId,userId,new Date());
    }

    @Override

    public Integer update(String userId, String bookId) {
        String sql = "update borrow set return_date = ?, status = 1 where user_id = ? and book_id = ?";
        return jdbcTemplate.update(sql,new Date(),userId,bookId);
    }
}
